package com.bdqn.zhao.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bdqn.zhao.pojo.CiApplyforsss;
import com.bdqn.zhao.service.CiApplyforsssService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 楼层表 前端控制器
 * </p>
 *
 * @author zhangsan
 * @since 2023-04-24
 */
@Controller
@RequestMapping("/ciApplyforsss")
public class CiApplyforsssController {

    @Resource
    CiApplyforsssService applyforsssService;
    @GetMapping("/selectApplyfor")
    @ResponseBody
    public String mohu(String name, Integer phone, String username, HttpServletRequest request){
        QueryWrapper<CiApplyforsss> queryWrapper = new QueryWrapper<>();
        if (name!=null){
            queryWrapper.like("name",name);
        }
        if (phone!=null){
            queryWrapper.like("phone",phone);
        }
        if (username!=null){
            queryWrapper.like("username",username);
        }
        List<CiApplyforsss> ciApplyforsssList = applyforsssService.list(queryWrapper);
        request.setAttribute("ciApplyforsssList",ciApplyforsssList);
        return "";
    }

    @PostMapping("updateApplyfor")
    @ResponseBody
    public String updateZt( Integer id, String status){
        CiApplyforsss applyforsss = applyforsssService.getById(id);
        applyforsss.setStatus(status);
        if (applyforsssService.updateById(applyforsss)){
            System.out.println("成功");
        }else {
            System.out.println("失败");
        }

        return "";

    }

    @PostMapping("delApplyfor")
    @ResponseBody
    public String del(Integer id){
        if(applyforsssService.removeById(id)){
            System.out.println("成功");
        }else {
            System.out.println("失败");
        }
        return "";
    }
}

